<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    #canvas {
      box-shadow: 2px 4px 6px #eee;
    }
  </style>
</head>
<body>
  <canvas id="canvas"></canvas>
</body>
<script src="../script/utils.js"></script>
<script src="../components/Ball.js"></script> 
<script>
  const canvas = document.getElementById('canvas')
  const ctx = canvas.getContext('2d')
  
  const W = canvas.width = 800
  const H = canvas.height = 600
  
  // let mouse = C.getOffset(canvas)
  let spring = 0.05, targetX = W / 2, targetY = H / 2
  let friction = 0.95

  const ball = new Ball({
    x: 80,
    y: 80,
    r: 40
  }).render(ctx)

  function drawFrame() {
    window.requestAnimationFrame(drawFrame)
    ctx.clearRect(0, 0, W, H)

    let ax = (targetX - ball.x) * spring
    ball.vx += ax
    ball.vx *= friction
    ball.x += ball.vx

    ball.render(ctx)
  }
  drawFrame()
</script>
</html>